<?php
include("./config.php");
include("./utils.php");
//checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>编辑软件信息</title>
  <?php include 'scripts-inc.php' ?>

  <script>
  var gData={};
  var appid = <?php echo $_GET["appid"]; ?>;
  $(function(){
    var u = 'query.php?op=one-app&appid='+appid;
    $.ajax({url:u,
      dataType:"json",
      async:true,
      success : function(msg, textStatus) { 
        var data = msg[0];
        if(data){
          $("#tid").val(data["appid"]);
          $("#tname").val(data["name"]);
          $("#tdes").val(data["des"]);
          $("#tdes_en").val(data["des_en"]);
          $("#tname_en").val(data["name_en"]);
          $("#tskin").val(data["skin"]);
          $("#tlogo").val(data["logo"]);
          $("#logo-img").attr("src", data['logo']);

          $(document).attr("title",'编辑[' + data['name']+']');//修改title值
          var appid = data['appid'];
          $("#goback a").attr("href","./show-app.php?appid="+appid);
          gData = data;
        }
      }
    },"text");

    function updateOp(op, v){
      var data = {
        appid:appid,
        op:op,
        value:v
      };

      $("#content").text("提交中...");
      $.post("update-data.php", data, function(msg){
        show_msg("#content", "修改完成");
      });
    }

    $("#save-name").click(function(){
      updateOp("save-app-name", $("#tname").val());
    });
    $("#save-des").click(function(){
      updateOp("save-app-des", $("#tdes").val());
    });
    $("#save-name-en").click(function(){
      updateOp("save-app-name-en", $("#tname_en").val());
    });
    $("#save-des-en").click(function(){
      updateOp("save-app-des-en", $("#tdes_en").val());
    });
    

    $("#save-skin").click(function(){
      updateOp("save-app-skin", $("#tskin").val());
    });
    $("#save-app-logo").click(function(){
      var tlogo = $("#tlogo").val();
      updateOp("save-app-logo", tlogo);
      $("#logo-img").attr("src", tlogo);
    });


  });//end of $(function(){

  </script>
</head>
<body>
<!-- template -->
<!-- end of template -->


<div id="wrapper">
<div id="container">
<!-- .................................................... -->

<div id="nav_data_src">
    <?php include 'navbars-inc.php' ?>
</div>

<div id="tcontainer" class="center">
<div class="container-fluid">
    <div class="form-group row">
      <label for="tid" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">ID</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <input type="" class="form-control" id="tid" name="tid" placeholder="" disabled/>
      </div>
      <a href="javascript:window.opener=null;window.open('','_self');window.close();"
       class="lang-close btn btn-danger col-xs-2 col-sm-1 col-md-1 col-lg-1 text-center" 
       id="" >关闭</a>
    </div>

    <div class="form-group row">
      <label for="tname" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">软件</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <input type="" class="form-control" id="tname" name="tname" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-name">保存</button>
    </div>
    <div class="form-group row">
      <label for="tdes" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">说明</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <textarea class="form-control" id="tdes" rows="5" name="tdes" placeholder=""></textarea>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-des">保存</button>
    </div>

    <!-- English -->
    <div class="form-group row">
      <label for="tname_en" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Software</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <input type="" class="form-control" id="tname_en" name="tname_en" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-name-en">Save</button>
    </div>
    <div class="form-group row">
      <label for="tdes_en" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Description</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <textarea class="form-control" id="tdes_en" rows="5" name="tdes_en" placeholder=""></textarea>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-des-en">Save</button>
    </div>

    <div class="form-group row">
      <label for="tskin" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">皮肤</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <input type="" class="form-control" id="tskin" name="tskin" placeholder="">
        <a class="btn btn-lg list-group-item-default" onclick="$('#tskin').val(0)">0</a>
        <a class="btn btn-lg list-group-item-danger" onclick="$('#tskin').val(1)">1</a>
        <a class="btn btn-lg list-group-item-info" onclick="$('#tskin').val(2)">2</a>
        <a class="btn btn-lg list-group-item-warning" onclick="$('#tskin').val(3)">3</a>
        <a class="btn btn-lg list-group-item-success" onclick="$('#tskin').val(4)">4</a>
        <a class="btn btn-lg list-group-item-primary" onclick="$('#tskin').val(5)">5</a>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-skin">保存</button>
    </div>


    <div class="form-group row">
      <label for="tlogo" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Logo</label>
      <div class="col-xs-7 col-sm-5 col-md-5 col-lg-5">
        <input type="" class="form-control" id="tlogo" name="tlogo" placeholder="">
        <img id="logo-img" style='max-width:128px;_width:expression(this.width > 128 ? "128px" : this.width);' src="" />
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-app-logo">保存</button>
    </div>


  <div class="clearfix"></div>
  <div class="form-group row">
    <div class="col-xs-3 col-sm-2 col-md-2 col-lg-2 text-center">
      <span id="content"></span>
    </div>
    <div class="col-xs-3 col-sm-1 col-md-1 col-lg-1 text-center" id="goback">
      <a href="./show-app.php" class="btn btn-lg btn-warning" >返回列表</a>
    </div>
    <div class="col-xs-3 col-sm-1 col-md-1 col-lg-1 text-center">
      <a href="./index.php" class="btn btn-lg btn-success" >返回首页</a>
    </div>
  </div>

</div>


</div> <!-- end of tcontainer -->

<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
